package com.egao.gps.utils;

import com.egao.common.core.damon.constant.UserConstant;
import com.egao.common.core.damon.utils.HttpsUtils;
import net.sf.json.JSONObject;

/**
 * @author Damon
 * @create 2021-08-23 16:30
 */
public class TxGetPlaceUtils {

  public static MapNavResults getAddress(){
//    String sendGet = HttpsUtils.get2("https://apis.map.qq.com/ws/place/v1/search?boundary=nearby(27.88396,121.124054,1000,1)");
    String sendGet = HttpsUtils.get2("https://apis.map.qq.com/ws/geocoder/v1/?location=29.31013,120.079672&key=" + UserConstant.TX_MAP_KEY + "&get_poi=1");
    JSONObject jsonObject=JSONObject.fromObject(sendGet);
    MapNavResults mapResult=new MapNavResults();
    if (jsonObject != null) {
      if (jsonObject.has("status") && jsonObject.getInt("status") == 0) {
        JSONObject result = JSONObject.fromObject(jsonObject.get("result"));
        if (result != null) {
          JSONObject addressComponent = JSONObject.fromObject(result.get("address_component"));
          if (addressComponent != null) {
            String city = addressComponent.getString("city");
            String district = addressComponent.getString("district");
            String township = addressComponent.getString("street");
            mapResult.setAddress(city + district + township);
          }
        }
      }
    }

    return mapResult;
  }

  public static void main(String[] args) {
    String res = TxGetPlaceUtils.getAddress().getAddress();
    System.out.println(res);
  }
}
